package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.MuchAssetBean;
import com.renwei.yunlong.utils.ACache;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by wangqi on 2017/11/23.
 * 多对象
 */

public class MuchObjectAdapter extends BaseRecyclerViewAdapter<MuchAssetBean> {

    private String titles[] = {"对象一", "对象二", "对象三", "对象四", "对象五",
            "对象六", "对象七", "对象八", "对象九", "对象十"};
    private String companyType;

    public MuchObjectAdapter(Context context) {
        super(context);
        companyType = ACache.get(context).getAsString("companyType");
    }

    @Override
    public void clean() {
        List<MuchAssetBean> list = new ArrayList<>();
        list.add(new MuchAssetBean());
        setData(list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyHolder(inflater.inflate(R.layout.item_mush_object, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MyHolder myHolder = (MyHolder) holder;

        MuchAssetBean bean = getItem(position);
        myHolder.tvObjectName.setText(titles[position]);
        myHolder.tvObject.setText(bean.getAssetName());

        myHolder.tvService.setText(bean.getDirectoryName());
        if ("1".equals(companyType)) {
            myHolder.rlProgress.setVisibility(View.GONE);
        } else {
            myHolder.rlProgress.setVisibility(View.VISIBLE);
        }
        myHolder.tvProgress.setText(bean.getSolutionState());

        myHolder.tvTitleService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnItemClickLitener.onItemClick(view, position);
            }
        });
        myHolder.rlObjectDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnItemClickLitener.onItemClick(view, position);

            }
        });
        myHolder.rlObject.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //对象选择
                mOnItemClickLitener.onItemClick(view, position);
            }
        });
        myHolder.rlService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //对象选择
                mOnItemClickLitener.onItemClick(view, position);
            }
        });

    }

    class MyHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_object_name)
        TextView tvObjectName;
        @Bind(R.id.rl_object_delete)
        RelativeLayout rlObjectDelete;
        @Bind(R.id.tv_object)
        TextView tvObject;
        @Bind(R.id.rl_object)
        RelativeLayout rlObject;
        @Bind(R.id.tv_service)
        TextView tvService;
        @Bind(R.id.rl_service)
        RelativeLayout rlService;
        @Bind(R.id.rl_progress)
        RelativeLayout rlProgress;
        @Bind(R.id.tv_title_service)
        TextView tvTitleService;
        @Bind(R.id.tv_progress)
        TextView tvProgress;

        public MyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
